home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / sndhrdw / gyruss.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  2KB  |  88 lines

  1. #include "driver.h"
  2. #include "cpu/i8039/i8039.h"
  3.  
  4.  
  5.  
  6. /* The timer clock which feeds the upper 4 bits of                        */
  7. /* AY-3-8910 port A is based on the same clock                            */
  8. /* feeding the sound CPU Z80.  It is a divide by                          */
  9. /* 10240, formed by a standard divide by 1024,                            */
  10. /* followed by a divide by 10 using a 4 bit                               */
  11. /* bi-quinary count sequence. (See LS90 data sheet                        */
  12. /* for an example).                                                       */
  13. /*                                                                        */
  14. /* Bit 0 comes from the output of the divide by 1024                      */
  15. /*       0, 1, 0, 1, 0, 1, 0, 1, 0, 1                                    */
  16. /* Bit 1 comes from the QC output of the LS90 producing a sequence of    */
  17. /*          0, 0, 1, 1, 0, 0, 1, 1, 1, 0                                    */
  18. /* Bit 2 comes from the QD output of the LS90 producing a sequence of    */
  19. /*         0, 0, 0, 0, 1, 0, 0, 0, 0, 1                                    */
  20. /* Bit 3 comes from the QA output of the LS90 producing a sequence of    */
  21. /*         0, 0, 0, 0, 0, 1, 1, 1, 1, 1                                     */
  22.  
  23. static int gyruss_timer[10] =
  24. {
  25.     0x00, 0x01, 0x02, 0x03, 0x04, 0x09, 0x0a, 0x0b, 0x0a, 0x0d
  26. };
  27.  
  28. READ_HANDLER( gyruss_portA_r )
  29. {
  30.     /* need to protect from totalcycles overflow */
  31.     static int last_totalcycles = 0;
  32.  
  33.     /* number of Z80 clock cycles to count */
  34.     static int clock;
  35.  
  36.     int current_totalcycles;
  37.  
  38.     current_totalcycles = cpu_gettotalcycles();
  39.     clock = (clock + (current_totalcycles-last_totalcycles)) % 10240;
  40.  
  41.     last_totalcycles = current_totalcycles;
  42.  
  43.     return gyruss_timer[clock/1024];
  44. }
  45.  
  46.  
  47.  
  48. static void filter_w(int chip,int data)
  49. {
  50.     int i;
  51.  
  52.  
  53.     for (i = 0;i < 3;i++)
  54.     {
  55.         int C;
  56.  
  57.  
  58.         C = 0;
  59.         if (data & 1) C += 47000;    /* 47000pF = 0.047uF */
  60.         if (data & 2) C += 220000;    /* 220000pF = 0.22uF */
  61.         data >>= 2;
  62.         set_RC_filter(3*chip + i,1000,2200,200,C);
  63.     }
  64. }
  65.  
  66. WRITE_HANDLER( gyruss_filter0_w )
  67. {
  68.     filter_w(0,data);
  69. }
  70.  
  71. WRITE_HANDLER( gyruss_filter1_w )
  72. {
  73.     filter_w(1,data);
  74. }
  75.  
  76.  
  77.  
  78. WRITE_HANDLER( gyruss_sh_irqtrigger_w )
  79. {
  80.     /* writing to this register triggers IRQ on the sound CPU */
  81.     cpu_cause_interrupt(1,0xff);
  82. }
  83.  
  84. WRITE_HANDLER( gyruss_i8039_irq_w )
  85. {
  86.     cpu_cause_interrupt(2,I8039_EXT_INT);
  87. }
  88.